﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MyDBconnection;

namespace Thesis_2
{
    public partial class frmMain : Form
    {
        private string online;
        DatabaseConnection dbconn = new DatabaseConnection();
        public frmMain()
        {
            InitializeComponent();
            mnuExit.Click += new EventHandler(mnuExit_Click);
            timer1.Tick += new EventHandler(timer1_Tick);
            this.FormClosing += new FormClosingEventHandler(frmMain_FormClosing);
            this.Load += new EventHandler(frmMain_Load);
            mnuProductEntry.Click += new EventHandler(mnuProductEntry_Click);
            mnuCategory.Click += new EventHandler(mnuCategory_Click);
            mnuUserReg.Click += new EventHandler(mnuUserReg_Click);
            mnuPrice.Click += new EventHandler(mnuPrice_Click);
            mnuSupplierEntry.Click += new EventHandler(mnuSupplierEntry_Click);
            mnuSupplierList.Click += new EventHandler(mnuSupplierList_Click);
            mnuStock.Click += new EventHandler(mnuStock_Click);
            mnuCustomerEntry.Click += new EventHandler(mnuCustomerEntry_Click);
            mnuListCustomer.Click += new EventHandler(mnuListCustomer_Click);
            mnuLogout.Click += new EventHandler(mnuLogout_Click);
        }

        void mnuLogout_Click(object sender, EventArgs e)
        {
            DialogResult result;
            result = MessageBox.Show("Are you sure you want to Log out?", "Log-out", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                dbconn.dbconnection();
                dbconn.AddData("Insert into tbluserlog(Username,Status)" + "VALUES ('" + lblUser.Text + "','" + label1.Text + "')");
                dbconn.DBClose();
                frmLogin frmL = new frmLogin();
                frmL.Show();
                this.Hide();
            }
            else
            {
                this.Show();

            }
        }
        void mnuPrice_Click(object sender, EventArgs e)
        {
            frmProductPrice frmP = new frmProductPrice();
            frmP.Show();
        }
        void mnuListCustomer_Click(object sender, EventArgs e)
        {
            frmCustomerList frmL = new frmCustomerList();
            frmL.Show();
        }
        void mnuCustomerEntry_Click(object sender, EventArgs e)
        {
            frmCustomerEntry frmC = new frmCustomerEntry();
            frmC.Show();
        }
        void mnuChangepass_Click(object sender, EventArgs e)
        {
            frmChangePassword frmC = new frmChangePassword();
            frmC.Show();

        }
        void mnuUpdateUser_Click(object sender, EventArgs e)
        {
            frmUpdateUser frmUp = new frmUpdateUser();
            frmUp.Show();

        }
        void mnuSubcat_Click(object sender, EventArgs e)
        {
            frmSubCategory frmS = new frmSubCategory();
            frmS.Show();

        }
        void mnuStock_Click(object sender, EventArgs e)
        {
            frmStock frmS = new frmStock();
            frmS.Show();
            
        }
        void mnuSupplierList_Click(object sender, EventArgs e)
        {
            frmSupplierlist frmSL = new frmSupplierlist();
            frmSL.Show();
            
        }
        void mnuSupplierEntry_Click(object sender, EventArgs e)
        {
            
            frmSupplierEntry frmS = new frmSupplierEntry();
            frmS.Show();
            
            
        }
        void mnuListofuser_Click(object sender, EventArgs e)
        {
            frmListofuser frmL = new frmListofuser();
            frmL.Show();
              
        }
        void mnuUserReg_Click(object sender, EventArgs e)
        {
           
            frmUserManager frmU = new frmUserManager();
            frmU.Show();
            
            
        }
        void mnuCategory_Click(object sender, EventArgs e)
        {
            frmCategory frmC = new frmCategory();
            frmC.Show();
           

        }
        void mnuProductEntry_Click(object sender, EventArgs e)
        {
            frmproduct frmP = new frmproduct();
            frmP.Show();
            frmP.lblUser.Text = lblUser.Text;
           
        }
        void frmMain_Load(object sender, EventArgs e)
        {
            lblUser.Text = online;
            label1.Text = "Logout";
        }
        public string passvalue
        {
            get { return online;}
            set { online = value; }
        }
        void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }
        void timer1_Tick(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Now;
            this.ToolStripStatusLabel4.Text = dt.ToString();
        }
        void mnuExit_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
        private void productListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmProductList frmP = new frmProductList();
            frmP.Show();
           
            
        }
    
    }
}
